package com.infocollect.project.api.ui;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.infocollect.common.utils.AesUtil;
import com.infocollect.common.utils.DateUtils;
import com.infocollect.common.utils.ServletUtils;
import com.infocollect.common.utils.StringUtils;
import com.infocollect.common.utils.oss.OSSClientUtil;
import com.infocollect.common.utils.oss.TYOSSClientUtil;
import com.infocollect.framework.config.OSSConfig;
import com.infocollect.framework.security.LoginUser;
import com.infocollect.project.api.comm.WebApiHelper;
import com.infocollect.project.api.entity.TappFromEntity;
import com.infocollect.project.api.req.BatchDicEnumReq;
import com.infocollect.project.api.req.SignatureReq;
import com.infocollect.project.api.req.SwagggerInfoReq;
import com.infocollect.project.api.service.ApiCommService;
import com.infocollect.project.api.service.ICommService;
import com.infocollect.project.api.service.ITappFromService;
import com.infocollect.project.api.vo.ApplyUserVO;
import com.infocollect.project.api.vo.AuditOperatorVo;
import com.infocollect.project.api.vo.AuditReportVo;
import com.infocollect.project.api.vo.DictionaryEnumVO;
import com.infocollect.project.form.vo.HeadEntityVO;
import com.infocollect.project.form.vo.R;
import com.infocollect.project.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;


@Api(value = "audit", tags = "网上审核方法")
@Controller
@RequestMapping("audit")
public class AudictController {

    @Resource
    private ITappFromService tappFromService;
    @Autowired
    private ApiCommService apiCommService;


    @PostMapping("queryApplyUserList")
    @ApiOperation("查询需要审核的数据")
    @ResponseBody
    public R<List<ApplyUserVO>> queryApplyUserList(@RequestParam("apiKey") String apiKey, @RequestParam("tableName") String tableName,
                                                   @RequestParam("cardId") String cardId, @RequestParam("examClass") String examClass) {
        if(!"dZAYJ5Q8J7BBNd1tzPI9nT4sC53TBH".equals(apiKey))
        {
            return R.newError("apiKey不正确");
        }
        return apiCommService.queryApplyUserList(tableName,cardId,examClass);
    }
    @PostMapping("auditOperator")
    @ApiOperation("审核数据")
    @ResponseBody
    public R<String> auditOperator(@RequestBody JSONObject param) {
        if(!"dZAYJ5Q8J7BBNd1tzPI9nT4sC53TBH".equals(param.getString("apiKey")))
        {
            return R.newError("apiKey不正确");
        }
        AuditOperatorVo audit = new AuditOperatorVo();

        audit.setAuditflag(param.getString("auditflag"));
        audit.setAuditremark(param.get("auditremark") == null ? "" : param.getString("auditremark"));
        audit.setFormId(-1L);
        audit.setTableNewId(param.getString("fid"));
        audit.setTableName(param.getString("tableName"));
        audit.setAuditby("-1");
        audit.setAuditbyname("自动审核");
        return tappFromService.auditOperator(audit);
    }

}
